package jsyf.oa.dao.device;

import com.alibaba.dubbo.common.utils.StringUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import jsyf.oa.entity.device.BrandStrockEntity;
import jsyf.oa.idao.BaseDao;
import jsyf.oa.ientity.IBaseEntity;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class BrandStrockDao extends BaseDao {

    @Override
    public IBaseEntity convertJson2Entity(JSONObject json) {
        return JSON.toJavaObject(json, BrandStrockEntity.class);
    }

    public BrandStrockDao() {
        super.iBaseEntity = new BrandStrockEntity();
    }

    public List<JSONObject> selectByBrandId(String brandId,String type) {
        StringBuffer sql = new StringBuffer();
        sql.append("SELECT\n" +
                "\tT_DVC_BRAND.FINANCE_COMPANY AS financeCompany,\n" +
                "\tT_DVC_BRAND.SORT_NO AS brandSortNo,\n" +
                "\tT_DVC_BRAND.AUTHENTICBRANDS_GROUP AS authenticbrandsGroup,\n" +
                "\tT_DVC_BRAND.BRAND_NAME AS brandName,\n" +
                "\tT_DVC_BRAND.MANUFACTURING_COMPANY AS manufacturingCompany,\n" +
                "\tT_DVC_BRAND.QUALITY_COMPANY AS qualityCompany,\n" +
                "\tT_DVC_BRAND.DEL_FLAG AS delFlag,\n" +
                "\tt_dvc_brand_stock.CONTACT AS contact,\n" +
                "\tt_dvc_brand_stock.SORT_NO AS stockSortNo,\n" +
                "\tt_dvc_brand_stock.BRAND_ADDRESS AS brandAddress,\n" +
                "\tT_DVC_BRAND.ID AS brandId,\n" +
                "\tt_dvc_brand_stock.TYPE AS type,\n" +
                "\tt_dvc_brand_stock.CONTACT_TEL AS contactTel\n" +
                "FROM\n" +
                "\tT_DVC_BRAND\n" +
                "LEFT JOIN t_dvc_brand_stock ON t_dvc_brand_stock.BRAND_ID = T_DVC_BRAND.ID\n" +
                "WHERE\n" +
                "\t1 = 1\n" +
                "AND T_DVC_BRAND.DEL_FLAG = 0\n");
        if (!StringUtils.isBlank(brandId)) {
            sql.append("AND T_DVC_BRAND.id = '" + brandId + "'\n");
        }
        if (!StringUtils.isBlank(type)) {
            sql.append(" group by t_dvc_brand_stock.BRAND_ADDRESS ");
        }
        sql.append("order by T_DVC_BRAND.sort_no,t_dvc_brand_stock.sort_no\n");
        return super.queryForJsonList(sql.toString());
    }
    public List<JSONObject> getContactsByAddress(String address) {
        StringBuffer sql=new StringBuffer();
        sql.append(" SELECT ");
        sql.append(" CONTACT as contact");
        sql.append(" FROM t_dvc_brand_stock WHERE 1=1 AND BRAND_ADDRESS=?");
        return super.queryForJsonList(sql.toString(),new Object[]{address});
    }
    public JSONObject getTelByContactByAddress(String condition,Object[] params) {
        StringBuffer sql=new StringBuffer();
        sql.append(" SELECT ");
        sql.append(" CONTACT as contact,");
        sql.append(" CONTACT_TEL as contactTel");
        sql.append(" FROM t_dvc_brand_stock WHERE 1=1 ");
        sql.append(condition);
        return super.queryForJsonObject(sql.toString(),params);
    }
    public List<JSONObject> getTransportMessage(){
        JSONObject t1=new JSONObject();
        t1.put("companyName","湘潭市均利物流有限公司");
        t1.put("contact","曾利波");
        t1.put("tel","15274857255");
        JSONObject t2=new JSONObject();
        t2.put("companyName","上海鹏远物流有限公司");
        t2.put("contact","徐化放");
        t2.put("tel","13816694426");
        JSONObject t3=new JSONObject();
        t3.put("companyName","江苏腾飞物流有限公司 ");
        t3.put("contact","贾小刚");
        t3.put("tel","18103516876");
        JSONObject t4=new JSONObject();
        t4.put("companyName","上海利星行物流有限公司");
        t4.put("contact","吕振明");
        t4.put("tel","18522292555");
        List<JSONObject> transports=new ArrayList<JSONObject>();
        transports.add(t1);
        transports.add(t2);
        transports.add(t3);
        transports.add(t4);
        return  transports;
    }
}
